package com.dana.clientdemo

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch

/**
 *
 * @ProjectName: clientDemo
 * @Package: com.dana.clientdemo
 * @ClassName: MyViewModel
 * @Description: java类作用描述
 * @Author: zhanwei.li
 * @CreateDate: 2024/7/16 17:33
 * @UpdateUser: 更新者
 * @UpdateDate: 2024/7/16 17:33
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
class MyViewModel:ViewModel() {

    private val viewEventsChanel = Channel<MainViewEvents>()
    val viewEvents = viewEventsChanel.receiveAsFlow()
    fun sendBitmap(){
        viewModelScope.launch {

        }
    }

    fun dispatchEvents(action: MainViewActions){
        when(action){
            is MainViewActions.SendBitmapAction ->{
                viewEventsChanel.trySend(MainViewEvents.SendBitmapEvent)
            }
            is MainViewActions.UnbindServiceAction ->{
                viewEventsChanel.trySend(MainViewEvents.UnbindEvent)
            }
            is MainViewActions.BindServiceAction ->{
                viewEventsChanel.trySend(MainViewEvents.BindEvent)
            }
            is MainViewActions.ImportBitmapsAction ->{
                viewEventsChanel.trySend(MainViewEvents.ImportBitmapEvent)
            }
            is MainViewActions.InitBDAction ->{
                viewEventsChanel.trySend(MainViewEvents.InitBDEvent)
            }
            is MainViewActions.StartActAction ->{
                viewEventsChanel.trySend(MainViewEvents.StartActivityEvent)
            }
            else ->{}
        }

    }

    sealed class MainViewActions{
        data object SendBitmapAction:MainViewActions()
        data object ImportBitmapsAction:MainViewActions()
        data object InitBDAction:MainViewActions()
        data object UnbindServiceAction:MainViewActions()
        data object BindServiceAction:MainViewActions()
        data object StartActAction:MainViewActions()
    }
    sealed class MainViewEvents{
        data object SendBitmapEvent:MainViewEvents()
        data object ImportBitmapEvent:MainViewEvents()
        data object InitBDEvent:MainViewEvents()
        data object StartActivityEvent:MainViewEvents()
        data object UnbindEvent:MainViewEvents()
        data object BindEvent:MainViewEvents()
    }
}